package userInterface;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JSpinner;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JTextField;

import controller.Controller;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ResourceBundle.Control;

public class RegisterFrame extends JFrame {

	private JPanel contentPane;
	private JTextField nameField;
	private JTextField surnameField;
	private JTextField emailField;
	private JTextField passwordField;
	private Controller controller;


	/**
	 * Create the frame.
	 */
	public RegisterFrame(final Controller controller) {
		this.controller = controller;
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 677, 332);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBounds(10, 11, 240, 272);
		contentPane.add(panel);
		panel.setLayout(null);
		
		JLabel lblNewLabel_2 = new JLabel("Name");
		lblNewLabel_2.setBounds(10, 28, 46, 14);
		panel.add(lblNewLabel_2);
		
		nameField = new JTextField();
		nameField.setBounds(10, 53, 220, 20);
		panel.add(nameField);
		nameField.setColumns(10);
		
		JLabel lblNewLabel_3 = new JLabel("Surname");
		lblNewLabel_3.setBounds(10, 84, 46, 14);
		panel.add(lblNewLabel_3);
		
		surnameField = new JTextField();
		surnameField.setBounds(10, 109, 220, 20);
		panel.add(surnameField);
		surnameField.setColumns(10);
		
		JLabel lblNewLabel_4 = new JLabel("Email");
		lblNewLabel_4.setBounds(10, 140, 46, 14);
		panel.add(lblNewLabel_4);
		
		emailField = new JTextField();
		emailField.setBounds(10, 165, 220, 20);
		panel.add(emailField);
		emailField.setColumns(10);
		
		JLabel lblNewLabel_5 = new JLabel("Password");
		lblNewLabel_5.setBounds(10, 196, 46, 14);
		panel.add(lblNewLabel_5);
		
		passwordField = new JTextField();
		passwordField.setBounds(10, 221, 220, 20);
		panel.add(passwordField);
		passwordField.setColumns(10);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBounds(260, 11, 391, 272);
		contentPane.add(panel_1);
		panel_1.setLayout(null);
		
		JButton registerButtton = new JButton("REGISTER");
		registerButtton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					controller.registerUser(nameField.getText(), surnameField.getText(), emailField.getText(), passwordField.getText());
					setVisible(false);
					SurveyFrame surveyFrame = new SurveyFrame(controller);
					surveyFrame.setVisible(true);
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					JOptionPane.showMessageDialog(new JFrame(), "Username exists!", "Error", JOptionPane.ERROR_MESSAGE);
				}
			}
		});
		registerButtton.setBounds(10, 238, 89, 23);
		panel_1.add(registerButtton);
	}
}
